package com.smart.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.smart.model.House;
import com.smart.model.User;
import com.smart.util.DBUtil;

public class HouseDAO {
	    //���ҷ����id
		public int getHouseId(int building_no,int room_no) throws SQLException
		{
			  Connection conn=DBUtil.getConnection();
			   String sql="select id from house where building_no=? and room_no=?";
			   PreparedStatement pSt=conn.prepareCall(sql);
			   pSt.setInt(1,building_no);
			   pSt.setInt(2,room_no);
			   ResultSet rs=pSt.executeQuery();
			   if(rs.next())
			   {
				   return rs.getInt(1);
			   }
			   else return -1;
		}
		
		//获取住宅信息 
				public House getHouse(int house_id) throws SQLException
				{
					System.out.println("houseDAO getHouse method");
					 Connection conn=DBUtil.getConnection();
					 String sql="select * from house where id=?";
					 PreparedStatement pSt=conn.prepareCall(sql);
					 pSt.setInt(1, house_id);
					 ResultSet res=pSt.executeQuery();
					 House house=new House();
					 if(res.next())
					 {
					   house.setId(res.getInt(1)); 
					   house.setCommunity_id(res.getInt(2));
					   house.setBuilding_id(res.getInt(3));
					   house.setRoom_no(res.getInt(4));
					   house.setArea(res.getFloat(5));
					 }
					 return house;
				}
}
